/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.visanyee.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author IT-Mafia
 */
@Entity
@Table(name = "rbh_risk_profile")
public class Profile implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Basic(optional = false)
    @Column(name = "PROFILE_ID", nullable = false, length = 40)
    private String profileId;
    @Column(name = "PROFILE_CREATE_DATETIME", insertable = false, updatable = false, nullable = false, columnDefinition = "timestamp default current_timestamp")
    @Generated(value = GenerationTime.INSERT)
    @Temporal(TemporalType.TIMESTAMP)
    private Date profileCreateDatetime;
    @Column(name = "PROFILE_ACCESS_DATETIME", insertable = false, updatable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date profileAccessDatetime;
    @Column(name = "PROFILE_LAST_ACCESS_DATETIME", insertable = false, updatable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date profileLastAccessDatetime;
    @Basic(optional = false)
    @Column(name = "PROFILE_STATUS", columnDefinition = "boolean default true", nullable = false)
    private boolean profileStatus;
    @JoinColumn(name = "OPDUSER", referencedColumnName = "loginname")
    @ManyToOne(fetch = FetchType.LAZY)
    private Opduser opduser;
    @JoinColumn(name = "RBH_RISK_ROLE", referencedColumnName = "ROLE_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private Role role;
    @JoinTable(name = "rbh_risk_permission", joinColumns = {
        @JoinColumn(name = "RBH_RISK_PROFILE", insertable = true, referencedColumnName = "PROFILE_ID", nullable = false, updatable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "RBH_RISK_WORKGROUP", insertable = true, referencedColumnName = "WORKGROUP_ID", nullable = false, updatable = false)})
    @ManyToMany(fetch = FetchType.LAZY, targetEntity = Workgroup.class)
    @Cascade({CascadeType.DETACH})
    @Fetch(FetchMode.SUBSELECT)
    private List<Workgroup> workgroupList;

    public Profile() {
    }

    public Profile(String profileId) {
        this.profileId = profileId;
    }

    public Profile(String profileId, Date profileCreateDatetime, boolean profileStatus, Opduser opduser, Role role) {
        this.profileId = profileId;
        this.profileCreateDatetime = profileCreateDatetime;
        this.profileStatus = profileStatus;
        this.opduser = opduser;
        this.role = role;
    }

    public String getProfileId() {
        return profileId;
    }

    public void setProfileId(String profileId) {
        this.profileId = profileId;
    }

    public Date getProfileCreateDatetime() {
        return profileCreateDatetime;
    }

    public void setProfileCreateDatetime(Date profileCreateDatetime) {
        this.profileCreateDatetime = profileCreateDatetime;
    }

    public boolean getProfileStatus() {
        return profileStatus;
    }

    public void setProfileStatus(boolean profileStatus) {
        this.profileStatus = profileStatus;
    }

    public Opduser getOpduser() {
        return opduser;
    }

    public void setOpduser(Opduser opduser) {
        this.opduser = opduser;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public Date getProfileLastAccessDatetime() {
        return profileLastAccessDatetime;
    }

    public void setProfileLastAccessDatetime(Date profileLastAccessDatetime) {
        this.profileLastAccessDatetime = profileLastAccessDatetime;
    }

    public List<Workgroup> getWorkgroupList() {
        return workgroupList;
    }

    public void setWorkgroupList(List<Workgroup> workgroupList) {
        this.workgroupList = workgroupList;
    }

    public Date getProfileAccessDatetime() {
        return profileAccessDatetime;
    }

    public void setProfileAccessDatetime(Date profileAccessDatetime) {
        this.profileAccessDatetime = profileAccessDatetime;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (profileId != null ? profileId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Profile)) {
            return false;
        }
        Profile other = (Profile) object;
        if ((this.profileId == null && other.profileId != null) || (this.profileId != null && !this.profileId.equals(other.profileId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.rbh.risk.entity.Profile[ profileId=" + profileId + " ]";
    }
}